/* AMX Mod X Config Ban functions
*/

#include <amxmodx>
#include <amxmisc>

#define CB_NAME_LEN 64
#define CB_IP_LEN 16
#define CB_STEAM_LEN 32


/**
* Registeres cvars from file,
* File should have format:
* cvar_name=default_value
* Comments are skipped
**/
stock register_cvar_from_file(const cfgFile[], &cvarCount, enumerate = 0)
{
	cvarCount = 0
	new lineNo = 0
	new nextLine = 1
	new iEnum = 1;
	while(nextLine > 0){
		new lineLen = 127
		new readLen
		new lineStr[128]
		new lineL[128]
		new lineR[128]
		
		new commStart = -1
		new commEnd = -1
		new commLine = -1
		
		nextLine = read_file ( cfgFile, lineNo, lineStr, lineLen, readLen)
		
		if(readLen >0){
			//remove all after comment //
			commLine = strfind(lineStr, "//")
			if(commLine >=0){
				split(lineStr, lineStr, lineLen, lineR, lineLen, "//")
			}
			commStart = strfind(lineStr, "/*")
			commEnd = strfind(lineStr, "*/")
			new bool:hasComment
			hasComment = commStart >=0 && commEnd >=0
			while(hasComment){
				split(lineStr, lineStr, lineLen, lineR, lineLen,"/*")
				split(lineR, lineL, lineLen, lineR, lineLen,"*/")
				add(lineStr, lineLen, lineR)
				commStart = strfind(lineStr, "/*")
				commEnd = strfind(lineStr, "*/")
				hasComment = commStart >=0 && commEnd >=0
			}
			//remove multiline comment /* */
			if(commStart>=0){
				while(nextLine >0 || commEnd >=0){
					nextLine = read_file ( cfgFile, nextLine, lineStr, lineLen, readLen)
					commEnd = strfind(lineStr, "*/")
				}				
			}
			else  {
				if(strfind(lineStr, "")>=0){
					strtok(lineStr, lineL, lineLen, lineR, lineLen, '=', 1)
					if(strlen(lineL) >0) {
						if(enumerate){
							format(lineL, 127,"%s%d",lineL,iEnum)
							iEnum++
						}
						register_cvar(lineL, lineR)
						cvarCount++
						server_print("Registered cvar %s with default value %s",lineL, lineR)
					}
				}
			}
		}
	}
	return 1
}


stock get_user_full_info(id, name[], ip[],steam[], nameLen = CB_NAME_LEN, ipLen = CB_IP_LEN, steamLen = CB_STEAM_LEN)
{
	get_user_name(id, name, nameLen)
	get_user_ip(id, ip, ipLen)
	get_user_authid(id, steam, steamLen)
	return 1
}
